<?php

namespace Admin\Controller;

use Think\Controller;
use Admin\Api\Uploader;
class ImageupController extends Controller {

    public function __construct() {
        parent::__construct();
        session("[start]");
        if (!isset($_SESSION['admininfo']) || $_SESSION['admininfo']['id'] < 1) {
            $this->redirect('Login/index');
        }
    }

    public function editorid() {               
        //上传配置
        $config = array(
            "savePath" => "Public/upload/", //存储文件夹
            "maxSize" => 1000, //允许的文件最大尺寸，单位KB
            "allowFiles" => array(".gif", ".png", ".jpg", ".jpeg", ".bmp")  //允许的文件格式
        );
        //上传文件目录
        $Path = "upload/";

        //背景保存在临时目录中
        //$config["savePath"] = $Path;
        $up = new Uploader("upfile", $config);
        $type = $_REQUEST['type'];
        $callback = $_GET['callback'];

        $info = $up->getFileInfo();
        /**
         * 返回数据
         */
        if ($callback) {
            echo '<script>' . $callback . '(' . json_encode($info) . ')</script>';
        } else {
            echo json_encode($info);
        }
    }

}
